package com.ianswer.px.user.service.impl;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.ianswer.common.orm.PublicDao;
import com.ianswer.px.user.entity.UsersWorkExperience;
import com.ianswer.px.user.service.UsersWorkExpService;

@Service("usersWorkExpService")
public class UsersWorkExpServiceImpl implements UsersWorkExpService {

	@Resource(name = "publicDao")
	private PublicDao publicDao;
	
	@Override
	public void save(UsersWorkExperience u) {
		UsersWorkExperience db = query(u.getUserId());
		if (db == null) {
			insert(u);
		} else {
			update(u);
		}
	}

	@Override
	public UsersWorkExperience query(long userId) {
		return publicDao.querySingle("worksExperience.get",userId);
	}
	
	@Override
	public void insert(UsersWorkExperience w) {
		publicDao.insert("worksExperience.insert", w);
	}
	
	@Override
	public void update(UsersWorkExperience w) {
		publicDao.update("worksExperience.update", w);
	}
	
	@Override
	public UsersWorkExperience get(long userId) {
		UsersWorkExperience r = query(userId);
		if (r != null) {
			if (StringUtils.isEmpty(r.getPost()) &&
				StringUtils.isEmpty(r.getComName()) &&
				StringUtils.isEmpty(r.getExperience1()) &&
				StringUtils.isEmpty(r.getExperience2()) &&
				StringUtils.isEmpty(r.getExperience3()) &&
				StringUtils.isEmpty(r.getExperience4()) &&
				StringUtils.isEmpty(r.getExperience5()) &&
				StringUtils.isEmpty(r.getExperience6()) &&
				StringUtils.isEmpty(r.getExperience7()) &&
				StringUtils.isEmpty(r.getExperience8()) &&
				StringUtils.isEmpty(r.getAward1()) &&
				StringUtils.isEmpty(r.getAward2()) &&
				StringUtils.isEmpty(r.getAward3()) &&
				StringUtils.isEmpty(r.getAward4()) &&
				StringUtils.isEmpty(r.getAward5())) {
				return null;
			}
		}
		return r;
	}
}
